package cn.com.darly.videoandroidpm.ui.games;

import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.AdapterView;
import android.widget.AdapterView.OnItemClickListener;
import android.widget.ListView;

import com.darly.dview.framework.ContentBinder;
import com.darly.dview.framework.ViewsBinder;
import com.darly.dview.widget.header.TitleView;

import cn.com.darly.videoandroidpm.R;
import cn.com.darly.videoandroidpm.base.BaseActivity;
import cn.com.darly.videoandroidpm.bean.PopInfo;
import cn.com.darly.videoandroidpm.common.ClassCache;
import cn.com.darly.videoandroidpm.ui.adapter.PMPopAdapter;

/** 休闲娱乐入口，使用GridView进行数据展示。
 * @author Darly/张宇辉/2018/3/19 9:45
 * @version 1.0/com.darly.darlyview.ui
 */
@ContentBinder(R.layout.activity_little_rest)
public class LittleRestActivity extends BaseActivity implements OnClickListener,OnItemClickListener{
    @ViewsBinder(R.id.id_base_title)
    public TitleView id_base_title;
    @ViewsBinder(R.id.id_little_rest_grid)
    ListView id_little_rest_grid;

    PMPopAdapter adapter;

    @Override
    protected void initView(Bundle savedInstanceState) {
        id_base_title.setTitle("休闲娱乐");
        id_base_title.removeBackground(R.drawable.ic_title_background);
    }

    @Override
    protected void loadData() {
        adapter  =new PMPopAdapter(ClassCache.getGame(),R.layout.item_pop_pm,this);
        id_little_rest_grid.setAdapter(adapter);
    }

    @Override
    protected void initListener() {
        id_base_title.setLeftBackOneListener(R.mipmap.ic_title_back,this);
        id_little_rest_grid.setOnItemClickListener(this);
    }
    @Override
    public void onClick(View v) {
        switch (v.getId()){
            case R.id.title_view_back_img:
                onBackPressed();
                break;
        }
    }

    @Override
    public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
        try {
            PopInfo info  = (PopInfo) parent.getItemAtPosition(position);
            Intent intent = new Intent();
            intent.setClass(this, Class.forName(info.getClazz()));
            startActivity(intent);
        } catch (ClassNotFoundException e) {
            e.printStackTrace();
        }
    }
}
